package com.lego.bean;

import java.util.Arrays;
import java.util.List;

public class Page<T> {
	private List<T> data;//商品集合
	private int pageNum;//页号
	private int pageSize;//页大小
	private int totalPages;//总页数
	private int totalRows;//总条数
	private boolean hasNext;//是否有下一页
	private boolean hasPrev;//是否有上一页
	private int[] navigatorNums;//有效页码
	private String keyWord;//穿入搜索的关键词
	private String goodsType;//传入的商品类型
	public List<T> getData() {
		return data;
	}
	public void setData(List<T> data) {
		this.data = data;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	public boolean isHasNext() {
		return hasNext;
	}
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
	public boolean isHasPrev() {
		return hasPrev;
	}
	public void setHasPrev(boolean hasPrev) {
		this.hasPrev = hasPrev;
	}
	public int[] getNavigatorNums() {
		return navigatorNums;
	}
	public void setNavigatorNums(int[] navigatorNums) {
		this.navigatorNums = navigatorNums;
	}
	
	public String getKeyWord() {
		return keyWord;
	}
	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}
	public String getGoodsType() {
		return goodsType;
	}
	public void setGoodsType(String goodsType) {
		this.goodsType = goodsType;
	}
	public Page(List<T> data, int pageNum, int pageSize, int totalRows,String keyWord,String goodsType) {
		this.data = data;
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalRows = totalRows;
		this.keyWord = keyWord;
		this.goodsType = goodsType;

		this.totalPages = totalPages;
		if((totalRows%pageSize)!=0) {
			this.totalPages = (totalRows/pageSize)+1;
		}else {
			this.totalPages = totalRows/pageSize;
		}
		
		if(pageNum<=1) {
			this.hasPrev = false;
		}else {
			this.hasPrev = true;
		}
		
		if(pageNum>=totalPages) {
			this.hasNext = false;
		}else {
			this.hasNext = true;
		}
		
		if(totalPages<10) {
			this.navigatorNums = new int[totalPages];
		}else {
			this.navigatorNums = new int[10];
		}
		
		if(pageNum<=5) {
			for (int i = 0; i < navigatorNums.length; i++) {
				navigatorNums[i] = i+1;
			}
		}else if(pageNum>5&&pageNum+5<=totalPages) {
			for (int i = pageNum-4,k = 0; i <= pageNum+5; i++,k++) {
				navigatorNums[k] = i;
			}
		}else {
			for (int i = totalPages-navigatorNums.length+1,k = 0; i <= totalPages; i++,k++) {
				navigatorNums[k] = i;
			}
		}

	    
	}
	public Page() {
		
	}
	@Override
	public String toString() {
		return "Page [data=" + data + ", pageNum=" + pageNum + ", pageSize=" + pageSize + ", totalPages=" + totalPages
				+ ", totalRows=" + totalRows + ", hasNext=" + hasNext + ", hasPrev=" + hasPrev + ", navigatorNums="
				+ Arrays.toString(navigatorNums) + ", keyWord=" + keyWord + ", goodsType=" + goodsType + "]";
	}
	
	
	
}
